Index: lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/lib.php,v
retrieving revision 1.484.2.18
diff -u -r1.484.2.18 lib.php
--- lib.php 3 Aug 2007 13:18:02 -0000 1.484.2.18
+++ lib.php 6 Aug 2007 16:38:14 -0000
@@ -262,8 +262,7 @@
}
}
-
-function build_mnet_logs_array($hostid, $course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='',
+function build_mnet_logs_array($hostid, $course, $user=0, $startdate=0, $finishdate, $order="l.time ASC", $limitfrom='', $limitnum='',
$modname="", $modid=0, $modaction="", $groupid=0) {
global $CFG;
@@ -337,9 +336,13 @@
$where .= " AND\n l.userid = '$user'";
}
- if ($date) {
- $enddate = $date + 86400;
- $where .= " AND\n l.time > '$date' AND l.time < '$enddate'";
+ if ($startdate) {
+ $enddate = $finishdate + 86400;
+ $joins[] = "l.time > '$startdate' AND l.time < '$enddate'";
+ }
+ if ($startdate) {
+ $enddate = $finishdate + 86400;
+ $where .= " AND\n l.time > '$startdate' AND l.time < '$enddate'";
}
$result = array();
@@ -353,7 +356,7 @@
return $result;
}
-function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='',
+function build_logs_array($course, $user=0, $startdate=0, $finishdate, $order="l.time ASC", $limitfrom='', $limitnum='',
$modname="", $modid=0, $modaction="", $groupid=0) {
// It is assumed that $date is the GMT time of midnight for that day,
@@ -409,10 +412,10 @@
$joins[] = "l.userid = '$user'";
}
- if ($date) {
- $enddate = $date + 86400;
- $joins[] = "l.time > '$date' AND l.time < '$enddate'";
- }
+ if ($startdate) {
+ $enddate = $finishdate + 86400;
+ $joins[] = "l.time > '$startdate' AND l.time < '$enddate'";
+ }
$selector = implode(' AND ', $joins);
@@ -424,12 +427,12 @@
}
-function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
+function print_log($course, $user=0, $startdate=0, $finishdate=0, $order="l.time ASC", $page=0, $perpage=100,
$url="", $modname="", $modid=0, $modaction="", $groupid=0) {
global $CFG;
- if (!$logs = build_logs_array($course, $user, $date, $order, $page*$perpage, $perpage,
+ if (!$logs = build_logs_array($course, $user, $startdate, $finishdate, $order, $page*$perpage, $perpage,
$modname, $modid, $modaction, $groupid)) {
notify("No logs found!");
print_footer($course);
@@ -538,13 +541,11 @@
print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&");
}
-
-function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
+function print_mnet_log($hostid, $course, $user=0, $startdate=0, $finishdate=0, $order="l.time ASC", $page=0, $perpage=100,
$url="", $modname="", $modid=0, $modaction="", $groupid=0) {
-
global $CFG;
- if (!$logs = build_mnet_logs_array($hostid, $course, $user, $date, $order, $page*$perpage, $perpage,
+ if (!$logs = build_mnet_logs_array($hostid, $course, $user, $startdate, $finishdate, $order, $page*$perpage, $perpage,
$modname, $modid, $modaction, $groupid)) {
notify("No logs found!");
print_footer($course);
@@ -646,13 +647,13 @@
}
-function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
+function print_log_csv($course, $user, $startdate, $finishdate, $order='l.time DESC', $modname,
$modid, $modaction, $groupid) {
$text = get_string('course')."\t".get_string('time')."\t".get_string('ip_address')."\t".
get_string('fullname')."\t".get_string('action')."\t".get_string('info');
- if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
+ if (!$logs = build_logs_array($course, $user, $startdate, $finishdate, $order, '', '',
$modname, $modid, $modaction, $groupid)) {
return false;
}
@@ -725,14 +726,14 @@
}
-function print_log_xls($course, $user, $date, $order='l.time DESC', $modname,
+function print_log_xls($course, $user, $startdate, $finishdate, $order='l.time DESC', $modname,
$modid, $modaction, $groupid) {
global $CFG;
require_once("$CFG->libdir/excellib.class.php");
- if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
+ if (!$logs = build_logs_array($course, $user, $startdate, $finishdate, $order, '', '',
$modname, $modid, $modaction, $groupid)) {
return false;
}
@@ -838,14 +839,14 @@
return true;
}
-function print_log_ods($course, $user, $date, $order='l.time DESC', $modname,
+function print_log_ods($course, $user, $startdate, $finishdate, $order='l.time DESC', $modname,
$modid, $modaction, $groupid) {
global $CFG;
require_once("$CFG->libdir/odslib.class.php");
- if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
+ if (!$logs = build_logs_array($course, $user, $startdate, $finishdate, $order, '', '',
$modname, $modid, $modaction, $groupid)) {
return false;
}
@@ -950,17 +951,16 @@
}
-function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
+function print_log_graph($course, $userid=0, $type="course.png", $startdate=0, $finishdate=0, $modid=0, $modaction="") {
global $CFG;
if (empty($CFG->gdversion)) {
echo "(".get_string("gdneed").")";
} else {
echo '';
+ '&user='.$userid.'&type='.$type.'&startdate='.$startdate.'&finishdate='.$finishdate.'&modid='.$modid.'&modaction='.$modaction.'" alt="" />';
}
}
-
function print_overview($courses) {
global $CFG, $USER;
@@ -2671,4 +2671,99 @@
return false;
}
-?>
+/**
+ * Select all log records for a given course
+ *
+ * @uses $CFG
+ * @uses DAYSECS
+ * @param int $courseid The id of the course as found in the 'course' table.
+ * @param string $coursestart ?
+ * @todo Finish documenting this function
+ */
+function get_logs_allusercourse($userid, $courseid, $startdate, $finishdate, $modid, $modaction) {
+ global $CFG;
+
+ if ($userid != 0) {
+ $selector = 'userid = \''. $userid .'\' AND ';
+ }
+
+ if ($modid !== 0) {
+ if ($modid == 'site_errors') {
+ $selector .= "( action='error' OR action='infected' ) AND ";
+ } else {
+ $selector .= 'cmid = \''. $modid .'\' AND ';
+ }
+ }
+
+ if ($modaction !== '') {
+ $firstletter = substr($modaction, 0, 1);
+ if (ctype_alpha($firstletter)) {
+ $selector .= "lower(action) LIKE '%" . strtolower($modaction) . "%'" . " AND ";
+ } else if ($firstletter == '-') {
+ $selector .= "lower(action) NOT LIKE '%" . strtolower(substr($modaction, 1)) . "%'" . " AND ";
+ }
+ }
+
+ if ($courseid) {
+ $courseselect = ' AND course = \''. $courseid .'\' ';
+ } else {
+ $courseselect = '';
+ }
+
+ $finishdate = $finishdate + DAYSECS;
+
+ return get_records_sql("SELECT floor((time - $startdate)/". DAYSECS .") as day, count(*) as num
+ FROM {$CFG->prefix}log
+ WHERE $selector time > '$startdate' AND time <= '$finishdate' $courseselect
+ GROUP BY day ");
+}
+
+/**
+ * Select all log records for a given course and day
+ *
+ * @uses $CFG
+ * @uses HOURSECS
+ * @param int $courseid The id of the course as found in the 'course' table.
+ * @param string $daystart ?
+ * @return object
+ * @todo Finish documenting this function
+ */
+function get_logs_alluserday($userid, $courseid, $daystart, $modid, $modaction) {
+ global $CFG;
+
+ if ($userid != 0) {
+ $selector = 'userid = \''. $userid .'\' AND ';
+ }
+
+ if ($modid !== 0) {
+ if ($modid == 'site_errors') {
+ $selector .= "( action='error' OR action='infected' ) AND ";
+ } else {
+ $selector .= 'cmid = \''. $modid .'\' AND ';
+ }
+ }
+
+ if ($modaction !== '') {
+ $firstletter = substr($modaction, 0, 1);
+ if (ctype_alpha($firstletter)) {
+ $selector .= "lower(action) LIKE '%" . strtolower($modaction) . "%'" . " AND ";
+ } else if ($firstletter == '-') {
+ $selector .= "lower(action) NOT LIKE '%" . strtolower(substr($modaction, 1)) . "%'" . " AND ";
+ }
+ }
+
+ if ($courseid) {
+ $courseselect = ' AND course = \''. $courseid .'\' ';
+ } else {
+ $courseselect = '';
+ }
+
+ $dayfinish = $daystart + DAYSECS;
+
+ return get_records_sql("SELECT floor((time - $daystart)/". HOURSECS .") as hour, count(*) as num
+ FROM {$CFG->prefix}log
+ WHERE $selector time > '$daystart' AND time <= '$dayfinish' $courseselect
+ GROUP BY hour ");
+}
+
+?>
\ No newline at end of file
Index: report/log/graph.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/report/log/graph.php,v
retrieving revision 1.4
diff -u -r1.4 graph.php
--- report/log/graph.php 25 Aug 2006 08:51:50 -0000 1.4
+++ report/log/graph.php 6 Aug 2007 16:32:12 -0000
@@ -8,7 +8,11 @@
$id = required_param('id', PARAM_INT); // Course ID
$type = required_param('type', PARAM_FILE); // Graph Type
$user = optional_param('user', 0, PARAM_INT); // Student ID
- $date = optional_param('date', 0, PARAM_INT); // A time of a day (in GMT)
+ $startdate = optional_param('startdate', 0, PARAM_INT); // A time of a start day (in GMT)
+ $finishdate = optional_param('finishdate', 0, PARAM_INT); // A time of a finish day (in GMT)
+ $modid = optional_param('modid', 0, PARAM_FILE); // number or 'site_errors'
+ $modaction = optional_param('modaction', '', PARAM_PATH); // an action as recorded in the logs
+ $currentcharset = get_string('thischarset');
if (! $course = get_record("course", "id", $id)) {
error("Course is misconfigured");
@@ -56,16 +60,16 @@
}
}
- $timestart = $coursestart = usergetmidnight($course->startdate);
+ $timestart = $coursestart = $startdate;
- if ((($timenow - $timestart)/86400.0) > 40) {
+ if ((($finishdate - $startdate)/86400.0) > 40) {
$reducedays = 7;
} else {
$reducedays = 0;
}
$i = 0;
- while ($timestart < $timenow) {
+ while ($timestart <= $finishdate) {
$timefinish = $timestart + 86400;
if ($reducedays) {
if ($i % $reducedays) {
@@ -81,7 +85,7 @@
$timestart = $timefinish;
}
- if ($rawlogs = get_logs_usercourse($user->id, $courseselect, $coursestart)) {
+ if ($rawlogs = get_logs_allusercourse($user->id, $courseselect, $startdate, $finishdate, $modid, $modaction)) {
foreach ($rawlogs as $rawlog) {
$logs[$rawlog->day] = $rawlog->num;
}
@@ -90,7 +94,11 @@
$graph = new graph(750, 400);
$a->coursename = $course->shortname;
- $a->username = fullname($user, true);
+ if ($user->id == 0){
+ $a->username = get_string('allparticipants');
+ } else {
+ $a->username = fullname($user, true);
+ }
$graph->parameter['title'] = get_string("hitsoncourse", "", $a);
$graph->x_data = $days;
@@ -112,7 +120,7 @@
$graph->parameter['x_label_angle'] = 0;
$graph->parameter['tick_length'] = 0;
-
+
$graph->parameter['shadow'] = 'none';
error_reporting(5); // ignore most warnings such as font problems etc
@@ -123,15 +131,15 @@
case "userday.png":
$site = get_site();
-
+
if ($course->id == $site->id) {
$courseselect = 0;
} else {
$courseselect = $course->id;
}
- if ($date) {
- $daystart = usergetmidnight($date);
+ if ($startdate) {
+ $daystart = usergetmidnight($startdate);
} else {
$daystart = usergetmidnight(time());
}
@@ -143,7 +151,7 @@
$hours[$i] = $i;
}
- if ($rawlogs = get_logs_userday($user->id, $courseselect, $daystart)) {
+ if ($rawlogs = get_logs_alluserday($user->id, $courseselect, $daystart, $modid, $modaction)) {
foreach ($rawlogs as $rawlog) {
$logs[$rawlog->hour] = $rawlog->num;
}
@@ -152,8 +160,12 @@
$graph = new graph(750, 400);
$a->coursename = $course->shortname;
- $a->username = fullname($user, true);
- $graph->parameter['title'] = get_string("hitsoncoursetoday", "", $a);
+ if ($user->id == 0){
+ $a->username = get_string('allparticipants');
+ } else {
+ $a->username = fullname($user, true);
+ }
+ $graph->parameter['title'] = get_string("hitsoncourse", "", $a);
$graph->x_data = $hours;
Index: report/log/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/report/log/index.php,v
retrieving revision 1.13.2.2
diff -u -r1.13.2.2 index.php
--- report/log/index.php 3 Aug 2007 13:18:00 -0000 1.13.2.2
+++ report/log/index.php 6 Aug 2007 10:38:00 -0000
@@ -23,6 +23,10 @@
$group = optional_param('group', -1, PARAM_INT); // Group to display
$user = optional_param('user', 0, PARAM_INT); // User to display
$date = optional_param('date', 0, PARAM_FILE); // Date to display - number or some string
+ $startdate = optional_param('startdate', 0, PARAM_FILE); // StartDate to display - number or some string
+ $finishdate = optional_param('finishdate', 0, PARAM_FILE); // FnishDate to display - number or some string
+ $startlogdate = optional_param('startlogdate', 0, PARAM_FILE); // StartDate to display - number or some string
+ $finishlogdate = optional_param('finishlogdate', 0, PARAM_FILE); // FnishDate to display - number or some string
$modname = optional_param('modname', '', PARAM_CLEAN); // course_module->id
$modid = optional_param('modid', 0, PARAM_FILE); // number or 'site_errors'
$modaction = optional_param('modaction', '', PARAM_PATH); // an action as recorded in the logs
@@ -68,8 +72,15 @@
}
$userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context));
}
- if ($date) {
- $dateinfo = userdate($date, get_string('strftimedaydate'));
+ if ($startdate > $finishdate) {
+ $startdate = $finishdate;
+ }
+ if ($startdate == 0||$finishdate == 0) {
+ $startdate = $startlogdate;
+ $finishdate = $finishlogdate;
+ }
+ if ($startdate) {
+ $dateinfo = userdate($startdate, get_string('strftimedaydate')) . ' - ' . userdate($finishdate, get_string('strftimedaydate'));
}
switch ($logformat) {
@@ -86,33 +97,41 @@
id\">$strlogs -> $userinfo, $dateinfo", '');
}
- print_heading(format_string($course->fullname) . ": $userinfo, $dateinfo (".usertimezone().")");
- print_mnet_log_selector_form($hostid, $course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
+ print_heading("$dateinfo (".usertimezone().")");
+ print_mnet_log_selector_form($hostid, $course, $user, $startdate, $finishdate, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
+ echo '